package com.example.a1725185505.works.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.a1725185505.works.R;

import java.util.List;


public abstract class BaseAdapter<T> extends RecyclerView.Adapter {
    public Context context;
    public LayoutInflater layoutInflater;
    public List<T> list;

    /*
     * 传入上下文
     * 动态加载布局
     */
    public BaseAdapter(Context context) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
    }

    /*
     * 设置数据
     */
    public void setList(List<T> list) {
        this.list = list;
        notifyDataSetChanged();
    }



    @NonNull
    @Override
    abstract public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType);

    /*
     * 获取数据个数
     */
    @Override
    public int getItemCount() {
        if (list == null)
            return 0;
        return list.size();
    }



    /**
     * Toast的简化
     */
    public void showToast(String text){
        Toast.makeText(context,text, Toast.LENGTH_SHORT).show();
    }


}
